@extends('layout.default')

@section('layout.content')

<div class="row">
    <div class="col-xs-12 align-right">
      <div style="margin-bottom: 15px;">
        <a href="{{route('student.publish.create')}}" class="btn btn-lg btn-success dialog"><i class="ace-icon fa fa-pencil-square-o"></i>新建花名册</a>
      </div>
    </div>
  </div><!-- /.row -->

  <div class="row">
    <div class="col-xs-12">
      <table class="table table-hover table-striped table-bordered">
        <thead>
          <tr>
            <th class="align-middle" style="width:110px;">花名册</th>
            <th class="align-middle" style="width:130px;">学期</th>
            <th class="center" style="width:100px;">班级限制</th>
            <th class="align-middle">门类</th>
            <th class="align-middle">班级</th>
            <th class="center" style="width:80px;">学生数</th>
            <th class="center" style="width:100px;">分支</th>
            <th class="center" style="width:100px;">状态</th>
          </tr>
        </thead>
        <tbody>
          @foreach ($publishs as $publish)
          <?php
            $termsCount = count($publish->details);
            if($termsCount <= 0) $termsCount = 1;
            $rowspan = $termsCount == 1 ? '' : "rowspan='{$termsCount}'";
            $detail = $publish->details->shift();
          ?>
            <tr>
              <td class="deploy" {!! $rowspan !!}>
                <a href="{{route('student.publish.edit',$publish->id)}}">{{ $publish->name }}</a>
              </td>
              <td class="" {!! $rowspan !!}>{{ $publish->term->name }}</td>
              <td class="align-top-center" {!! $rowspan !!}>{!! $publish->present()->limitStatus() !!}</td>
              <td class="align-middle" >{{ $detail->clase->category->name }}</td>
              <td class="align-middle" >{{ $detail->clase->name }}</td>
              <td class="center" >{{ $detail->clase->students($publish->id)->count() }}</td>
              <td class="align-top-center" {!! $rowspan !!}>{{ $publish->term->branch->name }}</td>
              <td class="align-top-center" {!! $rowspan !!}>
                 <div class="form-group">
                    <div class="btn-group">
                      <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle">
                        {!! $publish->present()->deployStatus() !!}
                        <i class="ace-icon fa fa-angle-down icon-on-right"></i>
                      </button>
                      <ul class="dropdown-menu dropdown-inverse dropdown-status">
                        <li>
                          <a href="javascript:;" class="inplan" data-id="{{$publish->id}}" data-status="{{$publish->status}}">
                            {!! $publish->present()->inverseStatus() !!}
                          </a>
                        </li>
                      </ul>
                    </div>
                  </div>
              </td>
            </tr>
            @if($rowspan != '')
              @foreach($publish->details as $detail)
              <tr>
                <td class="align-middle" >{{ $detail->clase->category->name }}</td>
                <td class="align-middle" >{{ $detail->clase->name }}</td>
                <td class="center" ><a href="{{route('student.publish.shows',array($publish->id,$detail->clase->id) ) }}">{{ $detail->clase->students($publish->id)->count() }}</a></td>
              </tr>
              @endforeach
            @endif

          @endforeach
        </tbody>
      </table>
    </div>
  </div>

@stop

@section('javascript')

  <script src="//cdn.bootcss.com/jquery-validate/1.19.1/jquery.validate.min.js"></script>
  <script src="{{URL::asset('assets/js/jquery-validate-methods.js')}}"></script>
  <script src="//cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>

  <script type="text/javascript">
    $(function () {

      $('.inplan').on('click', function () {

        var uri = "{{route('student.publish.change')}}";

        var id = $(this).data('id');
        var status = $(this).data('status');

        $.post(uri, {
          '_token': $("input[name='_token']").attr('value'),
          'id': id,
          'status': status,
        }, function (data) {
          console.log(data);
          layer.msg(data.message, {time:1000,shift: -1}, function () {
              if (data.status === true && data.url != null) {
                  $(window).attr('location', data.url);
              }
          });

        }, 'json').error(function (data) {
          layer.msg(data.responseJSON.message);
        });

    });

    $('.deploy').on('mouseenter', function () {
        $(this).find('.operate').show();
    }).on('mouseleave', function () {
        $(this).find('.operate').hide();
    });

  });
</script>
@stop
